package com.fenghongzhang.day014;

import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {
    private Button startIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        startIntent = (Button) findViewById(R.id.start_intent);

        MyReserve myReserve = new MyReserve();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.bawei.intentservice");
        registerReceiver(myReserve,intentFilter);

    }

    public void start_intent(View view) {
        Intent intent = new Intent(this, MyIntentService.class);
        startService(intent);

    }

    class MyReserve extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle extras = intent.getExtras();
            String json = extras.getString("json");

            Toast.makeText(context, json, Toast.LENGTH_SHORT).show();
        }
    }
}
